import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ff_flutter/screens/home/widgets/tab_bar/widgets/game_grid.dart';

class TabBarWidget extends StatefulWidget {
  @override
  State<TabBarWidget> createState() => _TabBarWidgetState();
}

class _TabBarWidgetState extends State<TabBarWidget>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  final List<String> _tabs = ['Explore Nearby', 'Game live'];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: _tabs.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        SizedBox(height: 50.h),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 32.w),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              SizedBox(
                width: 500.w,
                child: TabBar(
                  controller: _tabController,
                  labelColor: Colors.white,
                  unselectedLabelColor: Colors.grey,
                  labelStyle: TextStyle(
                    fontSize: 32.sp,
                    fontWeight: FontWeight.bold,
                  ),
                  unselectedLabelStyle: TextStyle(
                    fontSize: 32.sp,
                    fontWeight: FontWeight.normal,
                  ),
                  indicatorColor: const Color(0xFFE7568C),
                  indicatorWeight: 4.h,
                  indicatorSize: TabBarIndicatorSize.label,
                  dividerColor: Colors.transparent,
                  labelPadding: const EdgeInsets.all(0),
                  tabs: _tabs.map((String tab) => Tab(text: tab)).toList(),
                ),
              ),
              TextButton(
                onPressed: () {},
                child: Row(
                  children: [
                    Text(
                      "more",
                      style: TextStyle(
                        color: Colors.grey,
                        fontSize: 32.sp,
                      ),
                    ),
                    Icon(
                      Icons.chevron_right,
                      color: Colors.grey,
                      size: 32.sp,
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
        SizedBox(
          height: 900.h,
          child: TabBarView(
            controller: _tabController,
            children: [
              GameGrid(), // Explore Nearby 内容
              GameGrid(), // Game Live 内容
            ],
          ),
        ),
      ],
    );
  }
}
